#include <func.h>
#include<string.h>

int main(int argc,char *argv[])
{
    ARGS_CHECK(argc,2)
    DIR *dir;
    dir=opendir(argv[1]);
    ERROR_CHECK(dir,NULL,"opendir")
    struct dirent *p;
    off_t pos;
    while(p=readdir(dir))
    {
        printf("type=%d,len=%d,name=%s\n",p->d_type,p->d_reclen,p->d_name);
        if(!strcmp(p->d_name,"dir2"))
        {
            pos=telldir(dir);//保存当前目录读取位置
        }
    }
    seekdir(dir,pos);//返回保存的读取位置
    p=readdir(dir);
    printf("type=%d,len=%d,name=%s\n",p->d_type,p->d_reclen,p->d_name);
    rewinddir(dir);//回到目录头部
    p=readdir(dir);
    printf("type=%d,len=%d,name=%s\n",p->d_type,p->d_reclen,p->d_name);


    return 0;
}
